package com.tcmj.dining.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.tcmj.common.annotation.Log;
import com.tcmj.common.enums.BusinessType;
import com.tcmj.dining.domain.TzDiningRoom;
import com.tcmj.dining.service.ITzDiningRoomService;
import com.tcmj.common.core.controller.BaseController;
import com.tcmj.common.core.domain.AjaxResult;
import com.tcmj.common.utils.poi.ExcelUtil;
import com.tcmj.common.core.page.TableDataInfo;

/**
 * 餐厅Controller
 * 
 * @author tcmj
 * @date 2020-05-17
 */
@Controller
@RequestMapping("/system/room")
public class TzDiningRoomController extends BaseController
{
    private String prefix = "system/room";

    @Autowired
    private ITzDiningRoomService tzDiningRoomService;

    @RequiresPermissions("system:room:view")
    @GetMapping()
    public String room()
    {
        return prefix + "/room";
    }

    /**
     * 查询餐厅列表
     */
    @RequiresPermissions("system:room:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TzDiningRoom tzDiningRoom)
    {
        startPage();
        List<TzDiningRoom> list = tzDiningRoomService.selectTzDiningRoomList(tzDiningRoom);
        return getDataTable(list);
    }

    /**
     * 导出餐厅列表
     */
    @RequiresPermissions("system:room:export")
    @Log(title = "餐厅", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TzDiningRoom tzDiningRoom)
    {
        List<TzDiningRoom> list = tzDiningRoomService.selectTzDiningRoomList(tzDiningRoom);
        ExcelUtil<TzDiningRoom> util = new ExcelUtil<TzDiningRoom>(TzDiningRoom.class);
        return util.exportExcel(list, "room");
    }

    /**
     * 新增餐厅
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存餐厅
     */
    @RequiresPermissions("system:room:add")
    @Log(title = "餐厅", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TzDiningRoom tzDiningRoom)
    {
        return toAjax(tzDiningRoomService.insertTzDiningRoom(tzDiningRoom));
    }

    /**
     * 修改餐厅
     */
    @GetMapping("/edit/{diningId}")
    public String edit(@PathVariable("diningId") Long diningId, ModelMap mmap)
    {
        TzDiningRoom tzDiningRoom = tzDiningRoomService.selectTzDiningRoomById(diningId);
        mmap.put("tzDiningRoom", tzDiningRoom);
        return prefix + "/edit";
    }

    /**
     * 修改保存餐厅
     */
    @RequiresPermissions("system:room:edit")
    @Log(title = "餐厅", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TzDiningRoom tzDiningRoom)
    {
        return toAjax(tzDiningRoomService.updateTzDiningRoom(tzDiningRoom));
    }

    /**
     * 删除餐厅
     */
    @RequiresPermissions("system:room:remove")
    @Log(title = "餐厅", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tzDiningRoomService.deleteTzDiningRoomByIds(ids));
    }
}
